"use client";

import { Breadcrumb as AntBreadcrumb } from "antd";
import Link from "next/link";
import { usePathname } from "next/navigation";

const breadcrumbNameMap: Record<string, string> = {
  '/dashboard': '仪表盘',
  '/courses': '课程管理',
  '/tasks': '任务管理',
};

export function Breadcrumb() {
  const pathname = usePathname();
  const paths = pathname.split('/').filter(Boolean);
  
  const breadcrumbItems = paths.map((_, index) => {
    const url = `/${paths.slice(0, index + 1).join('/')}`;
    const isTasksPath = url.includes('/tasks');
    const isCourseIdPath = paths[index]?.length === 25; // cuid length

    let title = breadcrumbNameMap[url];
    if (isCourseIdPath) {
      title = '课程详情';
    } else if (isTasksPath) {
      title = '任务管理';
    }

    return {
      title: <Link href={url}>{title || paths[index]}</Link>,
    };
  });

  return (
    <AntBreadcrumb items={breadcrumbItems} />
  );
} 